package com.cyh.exp.controller;

import com.cyh.exp.mode.JwtUser;
import com.cyh.exp.mode.Result;
import com.cyh.exp.mode.User;
import com.cyh.exp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/demo")

public class AddUser {

    UserService userService;
    @Autowired
    public void setUserService(UserService userService){
        this.userService=userService;
    }
    @PostMapping("/simple/adduser")
    public Result addUSer(@RequestBody User user){
        return userService.addUser(user);
    }


    @GetMapping("/query/getById")
    public Result getById(@RequestParam("id") String id){
        System.out.println(id);

        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println(principal.toString());
//        System.out.println(SecurityContextHolder.getContext().getAuthentication().getName());
        return userService.getUserById(id);
    }
    @GetMapping("/query/getAll")
    public Result getAll(){
        return userService.getUserAll();
    }
    @GetMapping("/query/delete")
    public Result deleteById(@RequestParam("id") String id){
        return userService.deleteUserById(id);
    }
    @PostMapping("/query/update")
    public Result UpdateUser(@RequestBody User user){
        return userService.updateUser(user);
    }


}
